package com.wry.wry_test.algorithm;

import com.google.common.util.concurrent.ThreadFactoryBuilder;

import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @Author: wangrongyi
 * @Date: 2024/10/11 11:20
 * @Description:
 */
public class Day06 {
    public static void main(String[] args) {

        // create thread pool
        int core = Runtime.getRuntime().availableProcessors(); // get cpu core number
        ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat("insert_api_thread-pool").build();
        ThreadPoolExecutor insertApiThreadPoolExecutor = new ThreadPoolExecutor(1, core * 2, 60,
                TimeUnit.SECONDS, new LinkedBlockingQueue<>(2048), threadFactory);

        insertApiThreadPoolExecutor.submit(() -> {
            System.out.println("insertApiThreadPoolExecutor");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        });
        insertApiThreadPoolExecutor.submit(() -> {
            System.out.println("insertApiThreadPoolExecutor");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        });
        insertApiThreadPoolExecutor.submit(() -> {
            System.out.println("insertApiThreadPoolExecutor");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        });

        System.out.println(insertApiThreadPoolExecutor);

    }
}
